﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Business;
using System.Web.Security;
public partial class admin_View_Report : System.Web.UI.Page {
    //Create new encryption object
    Encryption objenc = new Encryption();
    protected void Page_Load(object sender, EventArgs e) {
        DropDownList commentDescriptionDDL = FormViewReport.FindControl("commentDescriptionDropDownList") as DropDownList;
        TextBox commentTextBox = FormViewReport.FindControl("commentDescriptionTextBox") as TextBox;
        //commentDescriptionDDL.Items.Add(new ListItem(String.Empty, "None Selected"));
        // Bind the selected dropdownlist to the textbox
        //commentDescriptionDDL.Items.Insert(0, new ListItem(String.Empty, "None Selected"));
        if (FormViewReport.CurrentMode == FormViewMode.Edit) {
            if (IsPostBack)
                commentTextBox.Text = GetComment(commentDescriptionDDL.SelectedItem.Text);
        }
    }
    /// <summary>
    /// Gets the comment decription
    /// from the database of the requested parameter
    /// </summary>
    /// <param name="comment_id">The comment_id.</param>
    /// <returns></returns>
    protected String GetComment(string comment_id) {
        CreateConn objcon = new CreateConn();
        string query = "SELECT commentDescription FROM StandardComments" +
            " WHERE comment_id = " + comment_id;
        DataTable dt = objcon.SQLConnDataTable(query);
        string comment = dt.Rows[0]["commentDescription"].ToString();

        return comment;
    }
    /// <summary>
    /// Handles the SelectedIndexChanged event of the GridViewStandardComments control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    /// <action>go to View_Comment.aspx with comment_id as query string</action>
    protected void GridViewStandardComments_SelectedIndexChanged(object sender, EventArgs e) {
        string comment_id = GridViewStandardComments.SelectedDataKey.Value.ToString();
        Server.Transfer("View_Comment.aspx?comment_id=" + comment_id);
    }
    /// <summary>
    /// Handles the Click event of the CreateStdCommentsButton control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    /// <action>go to Create_Comment.aspx with component_id and dateRecorded as query string</action>
    protected void CreateStdCommentsButton_Click(object sender, EventArgs e) {
        string component_id = objenc.EncodeUrl(Request.QueryString["component_id"].ToString());
        string dateRecorded = objenc.EncodeUrl(Request.QueryString["dateRecorded"].ToString());
        Server.Transfer("Create_Comment.aspx?component_id=" + component_id + "&dateRecorded=" + dateRecorded);
    }
    protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
    {


        Session.Contents.Remove("UserDetails");
        Session.Abandon();
        Session.Contents.RemoveAll();
        FormsAuthentication.SignOut();
        Response.Redirect("../Default.aspx");
    }

}
